using System;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

namespace UnityXEditor
{
    [Serializable]
    public class AutoDeleteBurstDebugInformationSetting
    {
        [SerializeField]
        public bool m_Enabled = false;
        public void OnGUI()
        {
            m_Enabled = EditorGUILayout.Toggle("自动删除发布后的_BurstDebugInformation_DoNotShip文件夹", m_Enabled);
        }
        public void Update()
        {
        }
    }
    public class AutoDeleteBurstDebugInformation
    {
        [PostProcessBuild()]
        public static void PostProcessBuild(BuildTarget target, string path)
        {
            if (target != BuildTarget.StandaloneWindows && target != BuildTarget.StandaloneWindows64)
                return;
            if (!UnityXSettings.platformSettings.windows.autoDeleteBurstDebugInformationSetting.m_Enabled)
                return;

            string dn = Path.GetDirectoryName(path);
            string fn = Path.GetFileNameWithoutExtension(path);
            string ddn = Path.GetFullPath(dn + "/" + fn + "_BurstDebugInformation_DoNotShip");
            if (Directory.Exists(ddn))
            {
                Directory.Delete(ddn, true);
            }
        }
    }
}